package first.niuke.simple;

import java.util.HashMap;

/**
 * @ClassName NC31
 * @description:
 * @author: 荣燊
 * @create: 2021-04-12 11:06
 **/
public class NC31 {
    public static void main(String[] args) {
        String str = "google";
        System.out.println(FirstNotRepeatingChar(str));
    }

    public static int FirstNotRepeatingChar(String str) {
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i=0; i<str.length();i++) {
            if (map.containsKey(str.charAt(i))) {
                map.put(str.charAt(i), 0);
            } else {
                map.put(str.charAt(i), 1);
            }
        }
        for (int i=0; i<str.length();i++) {
            if (map.get(str.charAt(i)) == 1) {
                return i;
            }
        }
        return -1;
    }

}
